<?php
// 后台登陆模块公共类
namespace Admin\Controller;

use Think\Controller;

class LoginingController extends Controller {
	protected $db;
	public function __construct() {
		parent::__construct ();
		$this->db = D ( 'User' );
	}
	public function index() {
		layout ( false ); // 临时关闭当前模板的布局功能
		
		$this->assign ( array (
				'list' => array (1,2,3,4,5,6 ) 
		) );
		$this->display ( 'index' );
	}
	
	// 登陆
	public function login() {
		$name = I ( 'post.name', '' );
		$password = md5 ( I ( 'post.password', '' ) );
		$interests = I ( 'post.interests', '' );
		
		$data = $this->db->where ( array (
				'user_id' => $name 
		) )->find ();
		if ($data ['password'] == $password) {
			$user_id = $data ['user_id'];
			$password = $data ['password'];
			session ( 'user_id', $user_id );
			session ( 'user_show', $data ['user_show'] );
			session ( 'user_show', $data ['user_show'] );
			session ( 'user_group', $data ['user_group'] );
			if ($interests == 1) {
				$user = $user_id . "=" . $password;
				$user_info = encrypt ( $user, C ( 'ADMIN_KEY' ) );
				cookie ( 'user_info', $user_info, 3600 ); // 指定cookie保存时间
			}
			echo true;
		} else {
			echo false;
		}
	}
	
	
	public function imgUpload(){
		//上传配置文件
		$config = array(
				'maxSize'       =>  2000000, //上传的文件大小限制 (0-不做限制)
				'exts'          =>  array('jpg','png','gif','bmp','jpeg'), //允许上传的文件后缀
		);
		 
		$file=new \Think\Upload($config);
		$file=$file->uploadOne($_FILES['Filedata']);
		 
		echo "/Uploads/".$file['savepath'].$file['savename'];
	}
	
	
}